#include "Game.h"
//--------------------------------------------------------------------------------
ns::Game::Game(HINSTANCE hInstance)
:
m_pkWindow(NULL),
m_hInstance(hInstance),
m_pkRenderer(NULL)
{

}
//--------------------------------------------------------------------------------
ns::Game::~Game()
{
	
}
//--------------------------------------------------------------------------------
bool ns::Game::StartUp()
{
	//variable temporal para almacenar el hWnd
	HWND hWnd = NULL;

	m_pkWindow = new Window(m_hInstance);
	m_pkRenderer = new Renderer(hWnd);

	if(!m_pkWindow)
		return false;
	
	if(!m_pkRenderer)
		return false;

	m_pkWindow->createWindow(800,600,hWnd);	
	m_pkRenderer->InitDX(hWnd);

	timer.FirstMeasure();

	if(OnStartUp())
		return true;


	return false;
}
//--------------------------------------------------------------------------------
bool ns::Game::Loop()
{
	//m_pkRenderer->IniBufferVert();
	m_pkRenderer->StartFrame();

	//en el testgame.cpp pongo add entity a cada cosa q quiera dibujar, y ya aca las tengo en esa variable y dibujo todas las q haya
	for (unsigned int i = 0;i<m_pvEntitiesToDraw.size();i++)
	{
		m_pvEntitiesToDraw[i]->Draw(m_pkRenderer);
	}

	if(OnLoop())
		return true;

	//Para medir los fps
	stringstream s;
	s<<"Tu Vieja v0.1 - FPS:"<<timer.getFPS();
	m_pkWindow->SetWindowTitle(s.str().c_str());
	timer.Measure();

	m_pkRenderer->EndFrame();

	return false;
}
//--------------------------------------------------------------------------------
bool ns::Game::ShutDown()
{
	bool bError = false;

	if(OnShutDown())
		bError = true;
	
	if(m_pkWindow)
	{
		delete m_pkWindow;
		m_pkWindow = NULL;
	}

	return bError;
}
//--------------------------------------------------------------------------------
/*ns::Renderer*  ns::Game::GetRenderer()
{
	return m_pkRenderer;
}*/
